package com.huanwei.mylab.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.huanwei.cc.base.Base_Z_Adapter;
import com.huanwei.cc.base.MyApplication;
import com.huanwei.cc.R;
import com.huanwei.cc.bean.Cons;
import com.huanwei.cc.bean.MEBQ;
import com.huanwei.cc.bean.MeEvent;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by ADM on 2017/12/4.
 * w我的标签适配器
 */

public class MYDP_Adapater extends Base_Z_Adapter {
    String zt;

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        // 查找控件
        if (null == convertView) {
            convertView = LayoutInflater.from(MyApplication.getInstance())
                    .inflate(R.layout.yyjy_item1, null);
            holder = new Holder();

            holder.tv2 = (TextView) convertView
                    .findViewById(R.id.tv2);
            holder.button = (ImageView) convertView
                    .findViewById(R.id.button);
            // 缓存Holder
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }


        MEBQ nrowDataeme = (MEBQ) getItem(position);
        holder.tv2.setText(nrowDataeme.getFishCategory_Name());
        if (Cons.xg) {
            holder.button.setVisibility(View.VISIBLE);
        } else {
            holder.button.setVisibility(View.INVISIBLE);
        }
        Log.e(TAG, "xx1111111111");
        holder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MeEvent myEvent = new MeEvent();
                myEvent.setType("remove");
                myEvent.setContent(((MEBQ) getItem(position)).getFishCategory_Name());
                EventBus.getDefault().post(myEvent);
                removeItem(position);
                notifyDataSetChanged();

            }
        });


        return convertView;
    }


    public class Holder {


        TextView tv2;
        ImageView button;
    }


}
